package cn.jiyun.function.controller;

import cn.jiyun.Result.Result;
import cn.jiyun.function.service.DemandService;
import cn.jiyun.pojo.DailyRecord;
import cn.jiyun.pojo.function.DemandSensitiveWord;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/demand")
public class DemandController {
    @Autowired
    DemandService demandService;
    /**
     * 查询所有需求敏感词信息
     *
     * @param pageNum 页码，默认为1
     * @param pageSize 每页记录数，默认为10
     * @param demandSensitiveWord 查询条件封装对象
     * @return 返回包含分页信息的结果对象
     */
    @RequestMapping("findAll")
    public Result findAll(@RequestParam(name="pageNum" ,defaultValue = "1")Integer pageNum,
                          @RequestParam(name="pageSize",defaultValue = "10") Integer pageSize,
                          @RequestBody DemandSensitiveWord demandSensitiveWord
    ) {
        PageInfo<DemandSensitiveWord> page = demandService.findAll(pageNum,pageSize,demandSensitiveWord);
        return Result.ok(page);
    }

    /**
     * 插入或更新需求敏感词信息
     *
     * @param demand 需求敏感词对象，包含要插入或更新的信息
     * @return 返回操作结果对象
     */
    @RequestMapping("insertDemand")
    public Result insertDemand(@RequestBody DemandSensitiveWord demand) {
        if (demand.getId() == null){
            demandService.insertDemand(demand);
        }else{
            demandService.updateDemand(demand);
        }
        return Result.ok();
    }

    /**
     * 根据ID查询需求敏感词信息，用于更新页面的数据填充
     *
     * @param id 需求敏感词的唯一标识
     * @return 返回包含需求敏感词信息的结果对象
     */
    @RequestMapping("toUpdate")
    public Result toUpdate( Integer id) {
        DemandSensitiveWord demand = demandService.findById(id);
        return Result.ok(demand);
    }
//    @RequestMapping("words")
//    public List<String> deny() {
//        return demandService.deny();
//    }
}
